package com.lywz.biz.service.food.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lywz.biz.common.dao.CommonDao;
import com.lywz.biz.common.entity.goodfood.ClassicFood;
import com.lywz.biz.dao.food.ClassicFoodDao;
import com.lywz.biz.service.food.ClassicFoodService;
import com.lywz.core.exception.ExceptionMes;
import com.lywz.core.exception.SSException;
import com.lywz.core.log.LogClerk;

@Service("classicFoodService")
public class ClassicFoodServiceImpl implements ClassicFoodService {

    @Autowired
    private CommonDao commonDao;

    @Autowired
    private ClassicFoodDao classicFoodDao;

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.ClassicFoodService#getOneClassicFoodById(int)
     */
    @Override
    public ClassicFood getOneClassicFoodById(int classicFoodId) throws SSException {
        try {
            return (ClassicFood) commonDao.queryById(ClassicFood.class, classicFoodId);
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }
    }

    @Override
    public List<ClassicFood> getTopTenList(int limit) throws SSException {

        try {
            return classicFoodDao.getTopTenClassicFoodList(limit);
        } catch (Exception e) {
            e.printStackTrace();
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.ClassicFoodService#getAllClassicFoodList()
     */
    @Override
    public List<ClassicFood> getAllClassicFoodList() throws SSException {
        try {
            return classicFoodDao.getClassicFoodListOrderByPower();
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }

    }

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.ClassicFoodService#deleteOneClassicFoodById(int)
     */
    @Override
    public boolean deleteOneClassicFoodById(int classicFoodId) throws SSException {
        try {
            commonDao.delete(getOneClassicFoodById(classicFoodId));
            return true;
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }
    }

    @Override
    public boolean updateClassicFood(ClassicFood classicFood) throws SSException {
        try {
            commonDao.update(classicFood);
            return true;
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.ClassicFoodService#addNewClassicFood(com.lywz.biz.common.entity.goodfood.ClassicFood)
     */
    @Override
    public boolean addNewClassicFood(ClassicFood classicFood) throws SSException {
        try {
            commonDao.insert(classicFood);
            return true;
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);

        }
    }

}
